import { app, globalShortcut, BrowserWindow, ipcMain, dialog } from 'electron/main'

let shortcuts = []

const shortcutUpdate = (win, ipcMain) => {
    ipcMain.on("installshortcut", (event, text) => {

        if (shortcuts.length > 0) {
            shortcuts.forEach(item => {
                globalShortcut.unregister(item.keyPressed);
            });
        }
        
        shortcuts = JSON.parse(text)

        shortcuts.forEach(item => {
            globalShortcut.register(item.keyPressed, function () {
                console.log(item.name);
                win.webContents.send("use-shortcut",item);
                // 执行快捷键对应的操作
            });
        });

    })
}

export default shortcutUpdate;